<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="css/Tree.css" />
<link rel="stylesheet" media="screen" href="css/docs.css" />
<!-- jQplot CSS END -->
<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<!-- DATATABLES CSS END -->
<script type="text/javascript" src="${ctx}/js/global_util.js"></script>
<script type="text/javascript" src="${ctx}/js/ajaxupload_tx.3.6.js"></script>
<table class="display" id="example">
	<thead>
		<tr>
			<th>选择</th>
			<th>文件名称</th>
			<th>上传时间</th>
			<th>上传者</th>
		</tr>
	</thead>
	<tbody>
		<s:if test="#request.resources==null || #request.resources.size<=0">
			<tr class="gradeA">
				<td colspan="4">暂无数据</td>
			</tr>
		</s:if>
		<s:else>
			<s:iterator var="res" status="sta" value="#request.resources">
				<s:if test="#sta.even">
					<tr class="gradeA">
				</s:if>
				<s:else>
					<tr class="gradeC">
				</s:else>
				<td><input type="checkbox" name="chk_resource"
					value="${res.id}" /></td>
				<td><a href="${res.coursewareUrl}">${res.coursewareName}</a></td>
				<td><fmt:formatDate value="${res.uploadDate}"
						pattern="yyyy-MM-dd hh:mm" /></td>
				<td><span id="GridView1_ctl04_Label1">${res.uploader}</span></td>
				</tr>
			</s:iterator>
		</s:else>
	</tbody>
</table>
<p>
	<%@ include file="/WEB-INF/pages/common/main_orgtab_pager_train_mater.jsp"%>
</p>
<div class="tabs side grid_12 leading">
	<div class="clear"></div>
	<div class="grid_12">
		<div class="form-action clearfix">
			<p>
				<input type="checkbox" value="1" id="form-updates-i2"
					onchange="checkAll(this,'chk_resource')" /><label
					for="form-updates-i2">全选</label> <a class="button"
					href="javascript:void(0)" onclick="deleteDatas('chk_resource')"><span
					style="background: url(${ctx}/images/img/cancel.png)" class="icon">&nbsp;</span>批量删除</a>
				<a id="resource_upload" class="button" href="javascript:void(0)"><span
					style="background: url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>上传</a>
			</p>
		</div>
	</div>
</div>
<div class="clear"></div>

<script type="text/javascript">
<!--
$(document).ready(function(){
	AjaxUpload.init('${ctx}/file/upload_resource.xhtml', "resource_upload", "", "");
});

function onUploadSubmit(file, ext) {
    //        if(ext!="png" || ext!="jpg"){
    //            alert("上传文件格式不正确");
    //            return;
    //        }
    //        alert("file=" + file + ", ext=" + ext)
}
function onUploadComplete(file, response) {
    var d;
    try {
        d = eval("[" + response + "]");
    }
    catch(err) {
        alert("文件上传错误！");
        return;
    }

    //var message = d[0].message;
    //上传出错
    if (d[0].success == false) {
        alert("上传出错")
        return;
    }
    //上传成功
    else {
        var realPath = d[0].result;
        $.ajax({
            type: 'POST',
            url:"${ctx}/ajax/train_materresource_upload.xhtml",
            data:{"planId":${planId},
            	"coursewareName":unescape(d[0].realName),
            	"coursewareUrl":realPath,
            	"uploader":"${com_sihai_ehr_session_user_name}"
            },
            dataType:"html",
            success: function(data){
                if(data == "success"){
                	alert("上传资料成功");
                	loadListContent("${ctx}${listAction}",${planId});
                }else{
                	alert("上传失败，请重新上传");
                }
            }
        });
    }
}
	
/**
* 删除数据
*/
function deleteDatas(name) {
	var checkIds = new Array();
	$("input[type='checkbox'][name='" + name + "']").each(function() {
		if (this.checked) {
			checkIds.push(this.value);
		}
	});
	if (checkIds.length == 0) {
		return;
	}
	if (confirm("确定要删除选中的数据吗？")) {
		doDeleteDatas("${ctx}/train/materresource_delete.xhtml",checkIds.join(","));
	}
}

/**
 * 删除指定数据集
 * @param url
 * @param ids
 */
function doDeleteDatas(url,ids) {
	$.ajax({
		type : "get",
		url : url,
		data: {"ids":ids},
		dataType : "json",
		success : function(data) {
			// load the grade list 
			//planId 
			loadListContent("${ctx}${listAction}",${planId});
		}
	});
}
//-->
</script>
